home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8096 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.5 KB

  1. Path: telepost.no!usenet
  2. From: Carsten Arnholm <ca@sesam.dnv.no>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Linking Fortran 77 with C++
  5. Date: 14 Feb 1996 16:21:53 GMT
  6. Organization: DNV
  7. Message-ID: <4ft271$q5a@nms.telepost.no>
  8. References: <4fsfi4$gqd@ulke.hiMolde.no>
  9. NNTP-Posting-Host: hugin.sesam.dnv.no
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1 (Windows; I; 32bit)
  14.  
  15. arildh@himolde.no (Arild Hoff) wrote:
  16. >I am developing a C++ application that must be linked together with 
  17. >existing Fortran 77 code.
  18. >I don't want to change the Fortran code because it is very large and 
  19. >working well.  
  20. >
  21. >My question is : Does anybody know about a Fortran compiler which can 
  22. >compile the Fortran 77 code to obj-files that can be linked with my C++ 
  23. >obj-files using the Borland 4.5 C++ linker ????
  24. >
  25. >I hope to get this work both under DOS and Windows.
  26. >
  27. >Please answer by e-mail : arildh@himolde.no
  28. >
  29. >
  30. >Arild Hoff
  31. >
  32.  
  33.  
  34. I also have the same situation: a large amount of tested F77 code which
  35. is being used in F77 programs, and which I want to re-use within a C++ program.
  36.  
  37. This is fairly easy with MS Visual C++ 4.0 and MS Fortran Powerstation (both
  38. are 32 bit compilers for Windows 95/NT).
  39.  
  40. As an experiment, I wanted to do basically the same within a 16 bit Windows 3.1
  41. environment, using Borland C++ 4.0 (somewhat old now). 
  42.  
  43. I found that the following worked, at least on an experimental level:
  44.  
  45. 1. Download the f2c (FORTRAN-to-C) conversion program from the Web.
  46.    Look at:  http://www.fortran.com/fortran/free.html
  47.    It is possible to get both binaries and source
  48.  
  49. 2. Write a little wrapper program in Borland C++ which
  50.    a: takes the name of a FORTRAN file as input
  51.    b: calls the f2c program, using a system("f2c [options] <fortran-file>") call.
  52.       This will generate a C-file. Notice that subroutine names are converted to lowercase
  53.       with a trailing underscore, and that CHARACTERs are converted to char* with an additional
  54.       int (string length value) at the end of the call.
  55.    c: calls the bcc (Borland command-line compiler), using a system("bcc [options] <c-file>")
  56.       This will generate a obj-file compatible with your system.
  57.    d: deletes the C-file using a remove(<C-file>)
  58.       You should consider the C-file as hidden "assembler code", because it is not readable
  59.       by humans, especially if you use Fortran IO (PRINT,READ,WRITE)
  60.  
  61.    Now you have a free 16 bit FORTRAN compiler compatible with Borland  !
  62.    I believe it will run under both DOS and Windows 3.1.
  63.  
  64. 3. Integrate your own FORTRAN compiler into the IDE of Borland, by declaring it as a translator
  65.    tool which translates from .f to .obj files. I think this is done via a Tools->customize ..
  66.    menu in Borland C++ 4.0, but I don't know version 4.5 
  67.    Make sure that the text editor also is default viewer for .f files.
  68.  
  69. 4. You should now be able to mix .f and .cpp files in your Borland projects.
  70.    When you make/build your software, borland C++ will compile your C++ code, and your
  71.    FORTRAN compiler will compile the .f files. It works !
  72.  
  73. 5. If you want to be really clever, you could make your C++ code portable between different
  74.    compilers/operating systems. To get ideas, I have some contributions on the Usenet. To find
  75.    these, use the AltaVista search engine at http://www.altavista.digital.com/
  76.    select Usenet and search for my name: Arnholm
  77.    There are several articles.
  78.  
  79.    another idea is to go directly to one of the articles at:
  80.  
  81.    http://ww2.altavista.digital.com/cgi-bin/news?msg@1364@comp%2elang%2efortran
  82.  
  83. Good luck,
  84.  
  85. Carsten Arnholm
  86.  
  87.  
  88.  
  89.